KEYPAD INTERFACING WITH ARM
This article presents a way to interface a keypad with ARM LPC2148 microcontroller to display alphabetical characters on an LCD module. Such kind of systems is commonly used in mobile phones to write an SMS and other texts.
Synopsis

An alphabetic keypad is similar to a numeric keypad, but it provides the complete set of alphabetical letters instead of numbers 0-9. This article presents a way to interface a keypad with ARM LPC2148 microcontroller to display alphabetical characters on an LCD module. Such kind of systems is commonly used in mobile phones to write an SMS and other texts. It can have further applications in displaying instant messages on other display systems such as LED matrices or other multi-segment displays.

Description

ARM is one of the major options available for embedded system developer. LPC2148 is the widely used IC from ARM-7 family. It is manufactured by Philips and it is pre-loaded with many inbuilt peripherals making it more efficient and a reliable option for the beginners as well as high end application developer.

ARM is a family of instruction set architectures for computer processors based on a reduced instruction set computing (RISC) architecture developed by British company ARM Holdings .A RISC-based computer design approach means ARM processors require significantly fewer transistors than typical processors in average computers. This approach reduces costs, heat and power use. These are desirable traits for light, portable, battery-powered devices including smartphones, laptops, tablet and notepad computers and other embedded systems. A simpler design facilitates more efficient multi-core CPUs and higher core counts at lower cost, providing higher processing power and improved energy efficiency for servers and supercomputers.


The ARM LPC2148 features are as follows:

1. Architecture: ARM v4T

2. Processor: ARM7-TDMI-S

3. Instructions: 32-bit ARM and 16-bit Thumb

4. Debug support: RT Embedded ICE, Embedded Trace interface

5. Static RAM: 32 KB

6. (On-chip)Additional: 8 KB for USB DMA

7. Flash Program: 512 KB

8. Mem.(On-chip)Programming: ISP/IAP via on-chip boot-loader program

9. GPIO No. of pins: up to 45 (fast GPIO lines, 5V tolerant), Configurable to fast GPIO

10. External Interrupts: Four; No. of pins: Nine

The ARM LPC2148 has two ports Port 0 and Port 1 respectively each port contains 32-bits for I/O operations. The Port 0 has 32-bit of I/O pins for individual directions and Port 1 has 32-bits of I/O pins for bidirectional purpose. It has two timers of each 32-bit. It has capable to storing 128-bit memory for interfacing.

Over the last few years, the ARM architecture has become the most pervasive 32-bitarchitecture in the world, with wide range of ICs available from various IC manufacturers. ARM processors are embedded in products ranging from cell/mobile phones to automotive braking systems. A worldwide community of ARM partners and third-party vendors has developed among semiconductor and product design companies, including hardware engineers, system designers, and software developers.

Keypad is organized as a matrix of switches in rows and column. Here uses a 4X3 matrix keypad and a 16x2 LCD for displaying the output of keypad. The concept of interfacing keypad with the MCU is simple. Every number is assigned two unique parameters, i.e., row and column number (n(R, C) for example 6 (2, 3)). Hence every time a key is pressed the number is identified by detecting the row and column number of the key pressed.

Initially all the rows are set to zero & columns are set to one by the controller and the columns are scanned to check if any key is pressed. In case no key is pressed the output of all the columns will be high. Whenever a key is pressed the row and column corresponding to the key will get short, resulting in the output of the corresponding column goes to go low (since we have made all the rows zero). This gives the column number of the pressed key.

Once the column number is detected, the controller set’s all the rows to high. Now one by one each row is set to zero by controller and the earlier detected column is checked if it becomes zero. The row corresponding to which the column gets zero is the row number of the digit. The above process is very fast and even if the switch is pressed for a very small duration of time the controller can detect the key which is pressed. The controller displays the number corresponding to the row and column on the LCD


Application

• Digital door locks

• Calculators

• Push-button telephones

• Vending machines

• ATMs

Proteus design for Keypad interfacing with ARM


Orcad design for Keypad interfacing with ARM


Keypad interfacing with ARM

/*  Name     : main.c
 *  Purpose  : Source code for LCD Interfacing with ARM LPC1248.
 *  Author   : Gemicates
 *  Date     : 2018-02-02
 *  Website  : www.gemicates.org
 *  Revision : None
 */
#include <lpc21xx.h>     				// header file for LPC21XX series
 
#define LCD (0xff<<8)
#define RS (1<<16)   					// register select pin
#define RW (1<<17) 				        // read write pin
#define EN (1<<18) 				      	// enable pin
 
#define r1 (1<<16)                            
#define r2 (1<<17)
#define r3 (1<<18)
#define r4 (1<<19)
#define c1 (1<<20)  
#define c2 (1<<21)
#define c3 (1<<22)
#define c4 (1<<23)
 
void delay(unsigned int time);                          // variable delay function
 
void lcd_ini(void);
void lcd_print(char *str);
void lcd_cmd(unsigned char command);
void lcd_dat(unsigned int data);
 
unsigned char keypad (void);
void keypad_delay(void);
 
int main (void)
   {
        PINSEL0 = 0x00000000;                           // select PORT0 as GPIO mode
        IODIR0 = 0Xffffffff;			        // make PORT0 pin as Output mode 
        PINSEL1 = 0x00000000;			        // select PORT1 as GPIO mode
        IODIR1 = 0x00f00000;
        
        lcd_ini();
        lcd_print("Press any key");
        lcd_cmd(0xc0);				        // bring cursor to second ROW 
 
        while(1)                		        // Repeat(loop) forever
          {
                lcd_dat(keypad());
          } 
        return 0;
   }
 
void keypad_delay(void)				        // delay function for keypad
   {
        unsigned int t1,t2;
        for(t1=0;t1<300;t1++)                 
                for(t2=0;t2<1275;t2++);
   }
 
 
 
unsigned char keypad (void)	                        // keypad operation function		
   {
        unsigned char key;
        IOCLR1|=(c1|c2|c3|c4|r1|r2|r3|r4);
        while(1)
           {
                IOCLR1|=c1;
                IOSET1|=(c2|c3|c4);                     // first column = 0
                
                if((IOPIN1&r1)==0)
                   {
                        key='7';
                        keypad_delay();
                        return key;
                   }
                else if((IOPIN1&r2)==0)
                  {
                        key='8';
                        keypad_delay();
                        return key;
                  }
                else if((IOPIN1&r3)==0)
                  {
                        key='9';
                        keypad_delay();
                        return key;
                  }
                else if((IOPIN1&r4)==0)
                  {
                        key='/';
                        keypad_delay();
                        return key;
                  }
                
                IOCLR1|=c2;
                IOSET1|=(c1|c3|c4);                     // second column = 0
                  
                if((IOPIN1&r1)==0)
                  {
                        key='4';
                        keypad_delay();
                        return key;
                  }
                else if((IOPIN1&r2)==0)
                  {
                        key='5';
                        keypad_delay();
                        return key;
                  }
                else if((IOPIN1&r3)==0)
                  {
                        key='6';
                        keypad_delay();
                        return key;
                  }
                else if((IOPIN1&r4)==0)
                  {
                        key='*';
                        keypad_delay();
                        return key;
                  }
                
                IOCLR1|=c3;
                IOSET1|=(c1|c2|c4);                     // third column = 0
 
                if((IOPIN1&r1)==0)
                  {
                        key='1';
                        keypad_delay();
                        return key;
                  }
                else if((IOPIN1&r2)==0)
                  {
                        key='2';
                        keypad_delay();
                        return key;
                  }
                else if((IOPIN1&r3)==0)
                  {
                        key='3';
                        keypad_delay();
                        return key;
                  }
                else if((IOPIN1&r4)==0)
                  {
                        key='-';
                        keypad_delay();
                        return key;
                  }
                
                IOCLR1|=c4;
                IOSET1|=(c1|c2|c3);                     // forth column = 0
 
                if((IOPIN1&r1)==0)
                  {
                        lcd_cmd(0x01);
                        keypad_delay();
                        
                  }
                else if((IOPIN1&r2)==0)
                  {
                        key='0';
                        keypad_delay();
                        return key;
                  }
                else if((IOPIN1&r3)==0)
                  {
                        key='=';
                        keypad_delay();
                        return key;
                  }
                else if((IOPIN1&r4)==0)
                  {
                        key='+';
                        keypad_delay();
                        return key;
                  }
          }
   }
 
void lcd_cmd(unsigned char command)                     // Function to send command to LCD
  {
        IO0CLR|=(RS|RW|EN|LCD);
        IO0SET|=(command<<8);
        IO0CLR|=RS;
        IO0CLR|=RW;
        IO0SET|=EN;
        delay(2);
        IO0CLR|=EN;
        delay(3);
  }
   
void lcd_dat(unsigned int data)                         // Function to send data to LCD       
  {
        IO0CLR|=(RS|RW|EN|LCD);
        IO0SET|=(data<<8);
        IO0SET|=RS;
        IO0CLR|=RW;
        IO0SET|=EN;
        delay(2);
        IO0CLR|=EN;
        delay(3);
  }
 
void lcd_print(char *str)
  {
        while(*str!='\0')
          {
                lcd_dat(*str);
                str++;
          }
  }
 
void lcd_ini(void)                                      // Funtion to Initialize LCD
  {
        delay(5);
        lcd_cmd(0X38); 		                        // for using 8-bit 2 row mode and 5x7 Dots of LCD
        lcd_cmd(0X0e);		                        // turn display ON for cursor blinking
        lcd_cmd(0X06);		                        // display ON
        lcd_cmd(0X01);		                        // clear screen
        delay(5);
        lcd_cmd(0X80);		                        // clear screen
  }
 
void delay(unsigned int time)                           // variable delay function 
  {
        unsigned int t1,t2;
        for(t1=0;t1<time;t1++)       
                for(t2=0;t2<1275;t2++);
  }

Error message here!

Show Error message here!


Forgot your password?

Error message here!

Send OTP

Error message here!

Show Error message here!


Lost your password? Please enter your email address. You will receive a password you Need.

Send Error message here!


Back to log-in

Close